function calenderFun(){

	var myScrollYear,myScrollMonth;
	var myDate = new Date();
	var yearText= myDate.getFullYear()+ '年';
	var monthText= myDate.getMonth() + '月';
	var yearStart = parseInt(yearText)-1900 + 1;
	var monthStart = parseInt(monthText) + 1;

/*********************************初始化iscroll**************************************/

	function loaded () {
		myScrollYear = new iScroll('wrapperYear', { 
			hScrollbar: false,
			vScrollbar: false,
			hideScrollbar: true,
			interactiveScrollbars: true,
			shrinkScrollbars: 'scale',
			bounce: false,
			fixedScrollbar: true,
			onScrollStart: function (){
				myScrollYear.scrollEnd = false;
			},
			onScrollEnd:function(data){
				chooseDateYear(data, myScrollYear);
			}
		});
		//定位到年开始位置
		myScrollYear.scrollToElement('#year li:nth-child('+yearStart+')',10);

		myScrollMonth = new iScroll('wrapperMonth', { 
			hScrollbar: false,
			vScrollbar: false,
			hideScrollbar: true,
			interactiveScrollbars: true,
			shrinkScrollbars: 'scale',
			bounce: false,
			fixedScrollbar: true,
			onScrollStart: function (){
				myScrollMonth.scrollEnd = false;
			},
			onScrollEnd:function(data){
				chooseDateMonth(data,myScrollMonth);
			}
		});
		//定位到月开始位置
		myScrollMonth.scrollToElement('#month li:nth-child('+monthStart+')',10);

	}

	document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
/*******************************************初始化iscroll结束********************************************************************/

//自定义插件结构
	var yearList,monthList;

	$('#mask_div').empty();

	var calenderDiv = '<div id="calender_content">';
        calenderDiv += '<div id="calender_header"><input id="cancle" type="button" value="关闭">日期选择<input id="submit" type="button" value="确定"></div>';
        calenderDiv += '<div id="calender_list"><div id="wrapperYear"><div id = "scrollYear"><ul id="year"></ul></div></div><div id="wrapperMonth"><div id = "scrollMonth"><ul id="month"></ul></div></div>';
        calenderDiv += '<p id="currentdate"><span class="arrow_left"></span><span class="arrow_right"></span></p></div></div>';

	$('#mask_div').append(calenderDiv);
	//添加年份
    for(var i=1900; i <= 2100; i++) {
    	yearList = '<li>'+i+'年</li>';
    	$('#year').append(yearList);
    }
    $('#year li:first-child').before('<li></li><li></li>');
    $('#year').append('<li></li><li></li>')
	//添加月份
    for(var j = 1; j <= 12; j++) {
    	monthList = '<li>'+j+'月</li>';
    	$('#month').append(monthList);
	    }
	    $('#month li:first-child').before('<li></li><li></li>');
	    $('#month').append('<li></li><li></li>');
	    $('#mask_div').show();

	//调用iscroll
	loaded();

	//获取滑动的距离
	function getTransLateY(obj){
		return parseFloat(obj.css('-webkit-transform').split(',')[5]);
	};
	var objYear = $("#year li");
	var objMonth = $("#month li");
	//年份
	function chooseDateYear(data,myScrollYear){
			if(myScrollYear.scrollEnd){
				return;
			};
				var yearPoTop = getTransLateY($('#scrollYear'));
				yearPoTop = - yearPoTop;
				var yearCurrent = Math.round((yearPoTop + 84.5)/36); 
				var currentPo = parseFloat((yearPoTop + 84.5)/36)-yearCurrent;
				currentPo = (currentPo-0.35)*36;

				if(!myScrollYear.scrollEnd){
					if (currentPo > 0) {
						myScrollYear.scrollTo(0,currentPo,1000,true);
						myScrollYear.scrollEnd = true;
					}else {
						myScrollYear.scrollTo(0,-currentPo,1000,true);
						myScrollYear.scrollEnd = true;
					}
				
					yearText = $(objYear[yearCurrent]).text();
				};						
	};
	//月份
	function chooseDateMonth(data,myScrollMonth){
			if(myScrollMonth.scrollEnd){
				return;
			};
				var monthPoTop = getTransLateY($('#scrollMonth'));
				monthPoTop = - monthPoTop;
				var monthCurrent = Math.round((monthPoTop + 84.5)/36); 
				var currentPo = parseFloat((monthPoTop + 84.5)/36)-monthCurrent;
				currentPo = (currentPo-0.35)*36;

				if(!myScrollMonth.scrollEnd){
					if (currentPo > 0) {
						myScrollMonth.scrollTo(0,currentPo,1000,true);
						myScrollMonth.scrollEnd = true;
					}else {
						myScrollMonth.scrollTo(0,-currentPo,1000,true);
						myScrollMonth.scrollEnd = true;
					}
				
					monthText = $(objMonth[monthCurrent]).text();
				};						
	};
	//关闭
	$('#cancle').on('click', function() {
		$('#mask_div').hide();
	});
	//确定
	$('#submit').on('click', function() {
		$('#mask_div').hide();
		$('#calender').text(yearText + monthText);
	});
}	
